package com.zhu.controller.system;

import com.zhu.pojo.Post;
import com.zhu.service.IPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaozhu
 * @since 2022-08-30
 */
@RestController
@RequestMapping("/post")
public class PostController {

    @Autowired
    private IPostService postService;

    /*
        获取所有的岗位信息
     */
    @RequestMapping("/all")
    public List<Post> getPost(Post post){
        return postService.getPost(post);
    }

    /*
        根据id获取对应岗位信息
     */
    @RequestMapping("/detail")
    public Post getPostById(@RequestParam("postId") Integer postId){
        return postService.getById(postId);
    }

    /*
        添加或修改对应岗位信息
     */
    @PostMapping("/action")
    public String postAction(@RequestBody Post post){
        if(post.getPostId()!=null){
            postService.updateById(post);
        }else{
            postService.save(post);
        }
        return "ok";
    }

    /*
        删除对应岗位信息
     */
    @PostMapping("/del")
    public String postDel(@RequestBody List<Integer> selectionList){
        postService.removeBatchByIds(selectionList);
        return "ok";
    }

}
